﻿Imports System.Data.SqlClient
Imports System.IO
Imports System.Windows
Imports System.Data


Public Class AyudaPersonas

    Public CnnStr As String = System.Configuration.ConfigurationSettings.AppSettings("ConnStr")

    Public Sub New()
        InitializeComponent()
    End Sub


    Private Sub AyudaPersonas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sqlCnn As New SqlClient.SqlConnection(CnnStr)
        Dim cmd_grilla As New SqlClient.SqlCommand("", sqlCnn)
        cmd_grilla.CommandType = CommandType.StoredProcedure
        cmd_grilla.CommandText = "SP_C_PERSONA"
        cmd_grilla.CommandTimeout = Integer.MaxValue

        Dim objSqlDataAdapter As New SqlClient.SqlDataAdapter(cmd_grilla)
        Dim objDataSet As New DataSet
        objSqlDataAdapter.Fill(objDataSet)

        Dim ListEscritorioVisualizacion As New List(Of ListaPersona)
        Dim objListaPersona As ListaPersona

        If Not objDataSet.Tables(0) Is Nothing Then
            For intIterador = 0 To objDataSet.Tables(0).Rows.Count() - 1
                objListaPersona = New ListaPersona
                System.Windows.Forms.Application.DoEvents()
                objListaPersona.DC_RUT = objDataSet.Tables(0).Rows(intIterador).Item(0).ToString()
                objListaPersona.DG_RAZON_SOCIAL = objDataSet.Tables(0).Rows(intIterador).Item(1).ToString()
                objListaPersona.DG_GIRO_COMERCIAL = objDataSet.Tables(0).Rows(intIterador).Item(2).ToString()
                objListaPersona.DG_MAIL = objDataSet.Tables(0).Rows(intIterador).Item(3).ToString()
                ListEscritorioVisualizacion.Add(objListaPersona)
            Next
        End If

        Me.grvPersonas.DataSource = ListEscritorioVisualizacion
        sqlCnn.Close()
        sqlCnn = Nothing

        Me.grvPersonas.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells
        Me.grvPersonas.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.grvPersonas.AutoResizeColumns()
        Me.grvPersonas.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
    End Sub

    Private Sub grvPersonas_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grvPersonas.CellContentClick
        Dim strDC_RUT As String = Me.grvPersonas.Item("DC_RUT", e.RowIndex).Value()
        frmEscritorioAprobaciones.txtProveedor.Text = strDC_RUT
        frmEscritorioAprobaciones.Show()
        Me.Close()
    End Sub

End Class